﻿import com.dinmax.flash.draw.common.Point
import com.dinmax.flash.draw.layout.Layout
import com.dinmax.flash.central.draw.*

class WindowManager extends com.dinmax.flash.draw.layout.composite.Composite {
	
	private var layout:Layout;
	private var layoutData:Object;
	private var location:Point;
	private var size:Point;
	
	private static var instance:WindowManager;
	
	public static function newInstance(){
		instance = new WindowManager(layout:Layout, location, size);
	};
	
	public static function getActive():WindowManager {
		return instance;
	};
	
	function WindowManager(layout:Layout, location:Point, size:Point){
		if(!layout) { 
			this.layout = new GridLayout();
		} else {
			this.layout = layout;
		};
		
		this.location = location;
		this.size = size;
		
	};
	
	//GETTERS AND SETTERS
	public function setLocation (newLocation:Point):Void {
		location = newLocation;
	}
	
	public function getLocation ():Point {
		return location;
	}

	public function setSize (newSize:Point):Void {
		size = newSize;
	}
	
	public function getSize ():Point {
		return size;
	}
	//
	
	// METODOS DE INTERFACE
	public function setLayout(layout:Layout):Void {
		this.layout = layout;
	};
	public function getLayout():Layout {
		return layout;
	};
	public function setLayoutData(layoutData:Object):Void {
		this.layoutData;
	};
	public function getLayoutData():Object {
		return layoutData;
	};
	//
	
	//UTILIDADES LOCAS
	public function setElementsPosition(clips:Array):Void {
		for(var i:Number = 0; i < clips.length; i++){
			var clip:MovieClip = clips[i];
			var check:Boolean = ( deltaPoint.getX() + clip._width ) < (endXY.getX() - startXY.getX());
			if(!check){
				deltaPoint.setY(deltaPoint.getY() + separator.getY() + clip._height);
				deltaPoint.setX(0);
			};
			
			clip._x = startXY.getX() + deltaPoint.getX();
			clip._y = startXY.getY() + deltaPoint.getY();
			deltaPoint.setX(deltaPoint.getX() + clip._width + separator.getX());
			
		}
	};
		
} // fin de clase